#include<stdio.h>
#include<iostream>
#include<string.h>
#include<stack>

using namespace std;

int main()
{
	stack<char>kuohao;
	char a[10000];
	int n,N,i,judge=1;
	scanf("%d",&N);
	for(i=1;i<=N;i++)
	{
	judge=1;
	getchar();
	cin>>a;
	for(n=0;n<strlen(a);n++)
	{
		/*if(a[0]==']'||a[0]==')') 
		{
			printf("No1\n");
		}*/
		if(a[n]=='['||a[n]=='(')
			kuohao.push(a[n]);
		else
		{
			if(kuohao.empty()==true)
			{
				judge=0;
				break;
			}
			else if((a[n]==']'&&kuohao.top()=='[')||(a[n]==')'&&kuohao.top()=='('))
				kuohao.pop();
			else
			{
				judge=0;
				break;
			}
		}
	}
	if(judge==0)
			printf("No\n");
	else
			printf("Yes\n");
	}
	return 0;
}
